//
//  TransRule2ViewController.m
//  FruitsWholesaler
//
//  Created by sgone-2 on 15/12/8.
//  Copyright © 2015年 sgone. All rights reserved.
//

#import "TransRule2ViewController.h"

@interface TransRule2ViewController ()

@property(nonatomic,strong) UITextField *textJL;
@property(nonatomic,strong) UITextField *textYF;
@property(nonatomic,strong) UITextField *textDS;
@property(nonatomic,strong) UITextField *textZJYF;



@property(nonatomic,strong) NSString *textJuli1;
@property(nonatomic,strong) NSString *textYunfei1;
@property(nonatomic,strong) NSString *textDianshu1;
@property(nonatomic,strong) NSString *textZJYunfei1;

@end

@implementation TransRule2ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    self.titleLabel.text = @"运费设置";
    self.backBtn.hidden = NO;
    self.rightBut.hidden = NO;
    [self.rightBut setTitle:@"保存" forState:UIControlStateNormal];
    self.rightBut.titleLabel.font = [UIFont systemFontOfSize:16];
    
    self.view.backgroundColor = BACKGROUND1;
    
    self.textJuli1 =   self.dataHandler.juli;
    self.textYunfei1 =  self.dataHandler.yunfei;
    self.textDianshu1 =  self.dataHandler.dianshu;
    self.textZJYunfei1 =  self.dataHandler.zjyunfei;
    
    [self initView];



}




#pragma mark 进行距离保存数据
-(void)initView
{
    
    
    
    UIView *view1 = [[UIView alloc]initWithFrame:CGRectMake(0, 84, ViewWidth, 50)];
    view1.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:view1];
    
    
    
    UILabel *lbl1 = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, 50)];
    lbl1.textColor = [UIColor grayColor];
    lbl1.font = [UIFont systemFontOfSize:15/FDLaOt];
    [view1 addSubview:lbl1];
    lbl1.text = @"  送货距离";
    
    
    self.textJL = [[UITextField alloc]initWithFrame:CGRectMake(75, 0, 120, 50)];
    self.textJL.borderStyle = UITextBorderStyleRoundedRect;
    self.textJL.keyboardType = UIKeyboardTypeNumberPad;
    self.textJL.textAlignment = NSTextAlignmentCenter;
    self.textJL.placeholder = @"请输入送货距离";
    self.textJL.borderStyle = UITextBorderStyleNone;
    self.textJL.font = [UIFont systemFontOfSize:14/FDLaOt];
    
    
    [view1 addSubview:self.textJL];
    
    
    UILabel *lbl2 = [[UILabel alloc]initWithFrame:CGRectMake(194, 0, 50/FDLaOt, 50)];
    lbl2.textColor = [UIColor grayColor];
    lbl2.font = [UIFont systemFontOfSize:15/FDLaOt];
    [view1 addSubview:lbl2];
    lbl2.text = @"公里内";
    
    
    
    
    
    
    
    //第二行数据
    UIView *view2 = [[UIView alloc]initWithFrame:CGRectMake(0, 84+51, ViewWidth, 50)];
    view2.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:view2];
    
    UILabel *lbl3 = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, 50)];
    lbl3.textColor = [UIColor grayColor];
    lbl3.font = [UIFont systemFontOfSize:15/FDLaOt];
    [view2 addSubview:lbl3];
    lbl3.text = @"  运        费";
    
    
    
    self.textYF = [[UITextField alloc]initWithFrame:CGRectMake(75, 0, 120, 50)];
    self.textYF.borderStyle = UITextBorderStyleRoundedRect;
    self.textYF.keyboardType = UIKeyboardTypeNumberPad;
    [view2 addSubview:self.textYF];
    self.textYF.textAlignment = NSTextAlignmentCenter;
    self.textYF.placeholder = @"请输入金额";
    self.textYF.borderStyle = UITextBorderStyleNone;
    self.textYF.font = [UIFont systemFontOfSize:14/FDLaOt];

    
    
    
    
    
    
    UILabel *lbl4 = [[UILabel alloc]initWithFrame:CGRectMake(194, 0, 50, 50)];
    lbl4.textColor = [UIColor grayColor];
    lbl4.font = [UIFont systemFontOfSize:15/FDLaOt];
    [view2 addSubview:lbl4];
    lbl4.text = @"元";
    

    
    
    
  
    
    
    
    
    //第三行数据
    UIView *view3= [[UIView alloc]initWithFrame:CGRectMake(0, 84+51+51, ViewWidth, 50)];
    view3.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:view3];
    
    
    UILabel *lbl21 = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, 50)];
    lbl21.textColor = [UIColor grayColor];
    lbl21.font = [UIFont systemFontOfSize:15/FDLaOt];
    [view3 addSubview:lbl21];
    lbl21.text = @"  起送店数";
    
    
    self.textDS = [[UITextField alloc]initWithFrame:CGRectMake(75, 0, 120, 50)];
    self.textDS.keyboardType = UIKeyboardTypeNumberPad;
    self.textDS.borderStyle = UITextBorderStyleRoundedRect;
    [view3 addSubview:self.textDS];
    self.textDS.textAlignment = NSTextAlignmentCenter;
    self.textDS.placeholder = @"请输入起送店数";
    self.textDS.borderStyle = UITextBorderStyleNone;;
    self.textDS.font = [UIFont systemFontOfSize:14/FDLaOt];
    
    
    
    
    UILabel *lbl22 = [[UILabel alloc]initWithFrame:CGRectMake(194, 0, 50, 50)];
    lbl22.textColor = [UIColor grayColor];
    lbl22.font = [UIFont systemFontOfSize:15/FDLaOt];
    [view3 addSubview:lbl22];
    lbl22.text = @"家";
    
    
    
    
    
    
    UIView *view4= [[UIView alloc]initWithFrame:CGRectMake(0, 84+51+51+51, ViewWidth, 50)];
    view4.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:view4];
    UILabel *lbl31 = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 175, 50)];
    lbl31.textColor = [UIColor grayColor];
    lbl31.font = [UIFont systemFontOfSize:15];
    [view4 addSubview:lbl31];
    lbl31.text = @"  超过送货距离增加运费";
    
    
    
    
    
    self.textZJYF = [[UITextField alloc]initWithFrame:CGRectMake(160, 0, 80, 50)];
    
    self.textZJYF.keyboardType = UIKeyboardTypeNumberPad;
    self.textZJYF.borderStyle = UITextBorderStyleRoundedRect;
    [view4 addSubview:self.textZJYF];
    self.textZJYF.textAlignment = NSTextAlignmentCenter;
    self.textZJYF.placeholder = @"请输入金额";
    self.textZJYF.borderStyle = UITextBorderStyleNone;
    self.textZJYF.font = [UIFont systemFontOfSize:14/FDLaOt];
    
    
    UILabel *label33 = [[UILabel alloc]initWithFrame:CGRectMake(245, 0, 50, 50)];
    label33.text = @"元";
    label33.font = [UIFont systemFontOfSize:15/FDLaOt];
    label33.textColor = [UIColor grayColor];
    
    [view4 addSubview:label33];
    
    
    
    
    
    self.textJL.text = self.textJuli1;
    self.textYF.text = self.textYunfei1;
    self.textDS.text = self.textDianshu1;
    self.textZJYF.text = self.textZJYunfei1;
    
    
    
    
    
    
    
}


-(void)rightButClick:(id)sender
{
    
    
    if (self.textJL.text.length == 0 || self.textYF.text.length == 0 || self.textDS.text.length == 0 || self.textZJYF.text.length == 0) {
        
        
        [self.view makeToast:@"请完善信息"];
        return;
        
        
    }
    else
    {
        
        
        
        //保存数据到单列
//        self.dataHandler.juli = self.textJL.text;
//        self.dataHandler.yunfei = self.textYF.text;
//        self.dataHandler.dianshu = self.textDS.text;
//        self.dataHandler.zjyunfei = self.textZJYF.text;
        
        
        //通过block传值传递到上一个页面
        NSArray *array = [[NSArray alloc]init];
        
        array= [NSArray arrayWithObjects:self.textJL.text,self.textYF.text,self.textDS.text,self.textZJYF.text, nil];
        
        
        //传值传递到上一个界面
        if (self.block) {
            
            self.block(array);
        }
        
        
        //通知进行数据刷新
        [[NSNotificationCenter defaultCenter] postNotificationName:@"shuaxian" object:nil];
        
        [self.navigationController popViewControllerAnimated:YES];
        
    }
}




@end
